/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Payment_Methods.java
 *
 * Created on 26 September 2010, 2:30:24 AM
 */

package CAT200;
import java.sql.*;
import java.util.*;
import java.text.*;
/**
 *
 * @author Wai Hong
 */
public class Payment_Methods extends javax.swing.JFrame {

    private String todayDate = getDateTime();
    double a = Double.valueOf(Order_Sumarry.productTotal.getText());
    int b = 0;
	static int c;
    /** Creates new form Payment_Methods */
    public Payment_Methods() {
        for(int i = 0; i < First_Menu.productData.size(); i++)
            b = b + Integer.parseInt(First_Menu.productData.elementAt(i).elementAt(1));

        a = a + 7;
        initComponents();
        itemQuantity.setText(String.valueOf(b));
        itemPrice.setText(Order_Sumarry.productTotal.getText());
        totalPrice.setText(String.valueOf(a));
        super.setSize(400, 250);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date DATE = new java.util.Date();
        return dateFormat.format(DATE);
        }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        EAST = new javax.swing.JRadioButton();
        WEST = new javax.swing.JRadioButton();
        CANCEL = new javax.swing.JButton();
        NEXT = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        itemQuantity = new javax.swing.JLabel();
        itemPrice = new javax.swing.JLabel();
        totalPrice = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Payment", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 18))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Total price  :");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Location  :");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Total payment  :");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Quantity of items :");

        buttonGroup1.add(EAST);
        EAST.setFont(new java.awt.Font("Tahoma", 0, 12));
        EAST.setText("East Malaysia (RM 10.00)");
        EAST.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EASTActionPerformed(evt);
            }
        });

        buttonGroup1.add(WEST);
        WEST.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        WEST.setSelected(true);
        WEST.setText("West Malaysia (RM 7.00)");
        WEST.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WESTActionPerformed(evt);
            }
        });

        CANCEL.setText("Cancel");
        CANCEL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CANCELActionPerformed(evt);
            }
        });

        NEXT.setText("Next");
        NEXT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NEXTActionPerformed(evt);
            }
        });

        itemQuantity.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        itemQuantity.setText("jLabel7");

        itemPrice.setFont(new java.awt.Font("Tahoma", 0, 12));
        itemPrice.setText("jLabel8");

        totalPrice.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        totalPrice.setText("jLabel9");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(EAST)
                            .addComponent(WEST)
                            .addComponent(itemQuantity)
                            .addComponent(itemPrice)
                            .addComponent(totalPrice))
                        .addGap(503, 503, 503))
                    .addComponent(jLabel6)))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(127, 127, 127)
                .addComponent(CANCEL)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NEXT)
                .addContainerGap(520, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {CANCEL, NEXT});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(itemQuantity))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(itemPrice))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(WEST)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EAST)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(totalPrice))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NEXT)
                    .addComponent(CANCEL))
                .addGap(93, 93, 93)
                .addComponent(jLabel6))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void WESTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WESTActionPerformed
        // TODO add your handling code here:
        a = Double.valueOf(Order_Sumarry.productTotal.getText());
        a = a + 7;
        totalPrice.setText(String.valueOf(a));
    }//GEN-LAST:event_WESTActionPerformed

    private void EASTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EASTActionPerformed
        // TODO add your handling code here:
        a = Double.valueOf(Order_Sumarry.productTotal.getText());
        a = a + 10;
        totalPrice.setText(String.valueOf(a));
    }//GEN-LAST:event_EASTActionPerformed

    private void CANCELActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CANCELActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_CANCELActionPerformed

    private void NEXTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NEXTActionPerformed
        // TODO add your handling code here:
        try
        {
            DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
            Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/CAT200-DB", "user", "123");
            Statement stmt = con.createStatement();
            ResultSet rsmt = stmt.executeQuery("select ORDER_NUMBER from ORDERS");

            while(rsmt.next())
                c = rsmt.getInt("ORDER_NUMBER");
            c++;

            stmt.execute("insert into ORDERS values " +
                    "(" +
                    "'" + c + "'," +
                    "'" + todayDate + "'," +
                    "'n'," +
                    totalPrice.getText() + "," +
                    "'" + First_Menu.UserAdmin + "'" +
                    ")");
            int j = 1;
            for(int i = 0; i < First_Menu.productData.size(); i++)
            {
                stmt.execute("insert into ORDERLINE values (" + j + "," + First_Menu.productData.elementAt(i).elementAt(1) + "," + "'" + c + "'," + "'" + First_Menu.productData.elementAt(i).elementAt(0) + "'," + First_Menu.productData.elementAt(i).elementAt(4) + ")");
                j++;
            }
        }
        catch(Exception e){ System.out.println(e); }
        new Cash_Payment_Method().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_NEXTActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Payment_Methods().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CANCEL;
    private javax.swing.JRadioButton EAST;
    private javax.swing.JButton NEXT;
    private javax.swing.JRadioButton WEST;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel itemPrice;
    private javax.swing.JLabel itemQuantity;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel totalPrice;
    // End of variables declaration//GEN-END:variables

}